package swing.components.tablemodels;

import java.util.Collections;

import javax.swing.table.AbstractTableModel;

import container.WeaponTraitDescriptions;
import container.Weapons;

/**
 * WeaponTrait table component.
 * 
 * @author Marcus
 * 
 */
public class WeaponTraitTableModel extends AbstractTableModel {
	/** Generated serial ID	 */
	private static final long serialVersionUID = -1472882966758947675L;

	private String[] headerName = new String[] { "Name", "Code", "Cost" };

	private WeaponTraitDescriptions weaponTraits;

	/**
	 * Constructor which creates this table on the basis of the passed
	 * {@link Weapons} object.
	 * 
	 * @param weapons
	 */
	public WeaponTraitTableModel(WeaponTraitDescriptions traits) {
		this.weaponTraits = traits;
		Collections.sort(this.weaponTraits.getTraitDescriptions());
	}
	
	/**
	 * Returns the number of the names in the header
	 * 
	 * @return number of names in the header
	 */
	public int getHeaderNameCount() {
		return this.headerName.length;
	}

	@Override
	public int getColumnCount() {
		return getHeaderNameCount();
	}

	@Override
	public int getRowCount() {
		if(this.weaponTraits == null){
			return 0;
		}
		return this.weaponTraits.getTraitDescriptions().size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		switch (columnIndex) {
		case 0:
			return this.weaponTraits.getTraitDescriptions().get(rowIndex)
					.getTraitName();
		case 1:
			return this.weaponTraits.getTraitDescriptions().get(rowIndex)
					.getTraitCode();
		case 2:
			return this.weaponTraits.getTraitDescriptions().get(rowIndex)
					.getRatingFormula();
		}
		return null;
	}
}
